﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace daStaticAnalyser.Analysers
{
    using daStaticAnalyser.Analysers;
    using daStaticAnalyser;
    using daBase.Objects;
    using daBase.Analyser;
    using daSyntaxAnalyser;
    using daSyntaxAnalyser.SyntaxTree;
    using daSyntaxAnalyser.Analysers;

    [AnalyserDefaultSettings("Оценка стилистики", "test", 0, "test")]
    class StilisticaAnalyzator : BaseStaticAnalyser
    {

        List<FileInf> FileInfos = new List<FileInf>();
        int CountLinesOfPart = 10;
        
        protected override void DoAnalyse(SyntaxTreeArgs e)
        {
            String FileName = e.Element.StartInfo.File;
            if (!FileInfos.Exists(s=> s.Name == FileName))
            {
                FileInfos.Add(new FileInf(FileName, LexicalAnalyser.FileSLOC[FileName], CountLinesOfPart));
            }

            if (e.Element.Comments == null){}
            else
            {
                foreach (TokenInfo info in e.Element.Comments)
                {
                    int CurPart = info.Line / CountLinesOfPart;
                    if (CurPart > 0) CurPart--;//Временно
                    FileInfos.Find(s=>s.Name == FileName).Comments[CurPart]++;
                }
            }
        }

        protected override void DoFinishAnalyse(EventArgs e)
        {
            for (int i = 0; i < FileInfos.Count; ++i)
            {
                int F = 0;
                for (int j = 0; j < FileInfos[i].Comments.Length; ++j)
                {
                    F += Math.Sign(((float)FileInfos[i].Comments[j])/ CountLinesOfPart - 0.1);
                }
                AddMetric("Оценка стилистики",
                          F,
                          FileInfos[i].Name,
                          FileInfos[i].Name,
                          1);
            }
            FileInfos.Clear();
        }
    }
}
